﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using ExtAspNet;

namespace GPCSC.Web
{
    public partial class dsqle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                datas();
            }
        }
        protected void datas()
        {
            string databasename = Usual.f_querystringToString("type");
            string sdf = Usual.f_querystringToString("id");
            try
            {
                sdf = "use[" + databasename + "] " + sdf;
                DataSet ds = dasql(sdf);
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
            catch (Exception ee)
            {
                Alert.Show(ee.ToString());
            }
        }
        protected DataSet dasql(string sql)
        {
            DataSet ds = new DataSet();
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString()))
            {
                SqlCommand cmd = new SqlCommand();
                PrepareCommand(cmd, connection, sql);
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    //DataSet ds = new DataSet();
                    try
                    {
                        da.Fill(ds, "ds");
                        cmd.Parameters.Clear();
                    }
                    catch (System.Data.SqlClient.SqlException ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        cmd.Dispose();
                        connection.Close();
                    }

                }
            }
            return ds;
        }
        private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, string cmdText)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();
            cmd.Connection = conn;
            cmd.CommandText = cmdText;

            cmd.CommandType = CommandType.Text;//cmdType;
        }
    }
}